/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sistemPembayaranSPP;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;
import tools.koneksi;

/**
 *
 * @author admin
 */
public class FormPembayaran extends javax.swing.JFrame {

    /**
     * Creates new form FormTagihan
     */
    public FormPembayaran() {
        initComponents();
        setTitle("Form Pembayaran");
        GregorianCalendar gc = new GregorianCalendar();
        notransaksi();
        tTanggal.setDate(gc.getTime());
        tNis.requestFocus();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        tNomerTransaksi = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        tNis = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        tNama = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        tKelas = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        tDibayar = new javax.swing.JTextField();
        tBelumDibayar = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        tTotalBayar = new javax.swing.JTextField();
        tTanggal = new com.toedter.calendar.JDateChooser();
        jPanel2 = new javax.swing.JPanel();
        bCetak = new javax.swing.JButton();
        btnBatal = new javax.swing.JToggleButton();
        btnKeluar = new javax.swing.JToggleButton();
        bsave = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(153, 153, 255));

        jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabel2.setText("No Transaksi ");

        tNomerTransaksi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tNomerTransaksiActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabel3.setText("Tanggal");

        jLabel4.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabel4.setText("NIS              ");

        tNis.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tNisActionPerformed(evt);
            }
        });
        tNis.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tNisKeyPressed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabel5.setText("Nama            ");

        jLabel6.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabel6.setText("Kelas             ");

        tKelas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tKelasActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabel7.setText("Dibayar         ");

        tDibayar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tDibayarActionPerformed(evt);
            }
        });
        tDibayar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tDibayarKeyPressed(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabel9.setText("Saldo siswa");

        tTotalBayar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tTotalBayarActionPerformed(evt);
            }
        });

        jPanel2.setBackground(new java.awt.Color(153, 153, 255));

        bCetak.setFont(new java.awt.Font("Times New Roman", 1, 18));
        bCetak.setText("CETAK");
        bCetak.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bCetakActionPerformed(evt);
            }
        });

        btnBatal.setFont(new java.awt.Font("Times New Roman", 1, 18));
        btnBatal.setText("BATAL");
        btnBatal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBatalActionPerformed(evt);
            }
        });

        btnKeluar.setFont(new java.awt.Font("Times New Roman", 1, 18));
        btnKeluar.setText("KELUAR");
        btnKeluar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnKeluarActionPerformed(evt);
            }
        });

        bsave.setFont(new java.awt.Font("Times New Roman", 1, 18));
        bsave.setText("SIMPAN");
        bsave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bsaveActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(169, Short.MAX_VALUE)
                .addComponent(bsave)
                .addGap(18, 18, 18)
                .addComponent(bCetak)
                .addGap(30, 30, 30)
                .addComponent(btnBatal)
                .addGap(36, 36, 36)
                .addComponent(btnKeluar)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bCetak)
                    .addComponent(btnBatal)
                    .addComponent(btnKeluar)
                    .addComponent(bsave))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel10.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabel10.setText("Total Bayar");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 87, Short.MAX_VALUE)
                                .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING))
                            .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(tBelumDibayar, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
                                    .addComponent(tDibayar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
                                    .addComponent(tTotalBayar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
                                    .addComponent(tKelas, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
                                    .addComponent(tNama, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
                                    .addComponent(tNis, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE))
                                .addGap(80, 80, 80))
                            .addComponent(tNomerTransaksi, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tTanggal, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel2)
                            .addComponent(tNomerTransaksi, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                            .addComponent(tTanggal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(tNis, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(tNama, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(tKelas, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jLabel10))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addComponent(tTotalBayar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(tDibayar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tBelumDibayar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(38, 38, 38))
        );

        jPanel3.setBackground(new java.awt.Color(0, 102, 204));

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 36));
        jLabel1.setText("PEMBAYARAN SPP");

        jLabel15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/logo.jpg"))); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jLabel15)
                .addGap(120, 120, 120)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(118, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tNomerTransaksiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tNomerTransaksiActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tNomerTransaksiActionPerformed

    private void tNisKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tNisKeyPressed
        if (java.awt.event.KeyEvent.VK_ENTER == evt.getKeyCode()) {
            try {
                // TODO add your handling code here:

                TagihanSiswa s = Kontrol.getKoneksiTagihan().getDataTagihanOtomatis(tNis.getText());
                if (s != null) {
                    tNama.setText(s.getNama());
                    tKelas.setText(s.getNama_kelas());
                    tTotalBayar.setText(s.getTotal().toString());
//                    tDibayar.setText(s.getBiayaBulan().toString());

                } else {
                }
            } catch (SQLException ex) {
                Logger.getLogger(FormPembayaran.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }//GEN-LAST:event_tNisKeyPressed

    private void tDibayarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tDibayarKeyPressed
        // TODO add your handling code here:
//         if (evt.getKeyCode()==10) {
//         int kembali;
//         int diBayar=Integer.parseInt(tDibayar.getText());
//         int totalBayar=Integer.parseInt(tTotalBayar.getText());
//         kembali = totalBayar - diBayar;
//         double a = Integer.parseInt(tTotalBayar.getText()) - Integer.parseInt(tDibayar.getText());
//         tBelumDibayar.setText(String.valueOf(a));
//         totalBayar=kembali;
//              try {
        // TODO add your handling code here:
//            double a = Double.parseDouble(tTotalBayar.getText());
//                   double b = Double.parseDouble(tDibayar.getText());
//                   double total = a-b;
//            tBelumDibayar.setText(Double.toString(total));
//            Kontrol.getKoneksiTagihan().updatePembayaran(a);
//        } catch (SQLException ex) {
//            Logger.getLogger(FormPembayaran.class.getName()).log(Level.SEVERE, null, ex);
//        }
    }//GEN-LAST:event_tDibayarKeyPressed

    private void btnBatalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBatalActionPerformed
        // TODO add your handling code here:
        kosongkan();
    }//GEN-LAST:event_btnBatalActionPerformed

    private void btnKeluarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnKeluarActionPerformed
        // TODO add your handling code here:
        this.dispose();
        FormUtama utama = new FormUtama();
        utama.setVisible(true);


    }//GEN-LAST:event_btnKeluarActionPerformed

    private void tKelasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tKelasActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tKelasActionPerformed

    private void bsaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bsaveActionPerformed
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yy");
        Date tanggal = tTanggal.getDate();

        Pembayaran k = new Pembayaran();

        k.setTanggalBayar(tanggal);
        k.setNoTransaksi(tNomerTransaksi.getText());
        k.setNIS(tNis.getText());
        k.setNamaKelas(tKelas.getText());
        k.setDibayar(Double.parseDouble(tDibayar.getText()));
        k.setKembali(Double.parseDouble(tBelumDibayar.getText()));
        k.setTotalBayar(Double.parseDouble(tBelumDibayar.getText()));

        try {
            Kontrol.getKoneksiTagihan().tambahDataPembayaran(k);
            JOptionPane.showMessageDialog(this, "data pembayaran berhasil disimpan");
            Kontrol.getKoneksiTagihan().updatePembayaran(k);
//            notransaksi();
//            kosongkan();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(this, "data pembayaran gagal disimpan" + " \n error: " + ex.getMessage());
        }
        //        try {
//            //        try {
//            // TODO add your handling code here:
//            //            double a = Double.parseDouble(tTotalBayar.getText()) - Double.parseDouble(tDibayar.getText());
//            //            tBelumDibayar.setText(String.valueOf(a));
//            Pembayaran uk = new Pembayaran();
//            uk.setNIS(tNis.getText());
//            uk.setTotalBayar(Double.parseDouble(tBelumDibayar.getText()));
//            Kontrol.getKoneksiTagihan().updatePembayaran(uk);
//            JOptionPane.showMessageDialog(this, "Pembayaran berhasil dilakukan");
//            //        } catch (SQLException ex) {
//            //            Logger.getLogger(FormPembayaran.class.getName()).log(Level.SEVERE, null, ex);
//            //        }
//            kosongkan();
//        } catch (SQLException ex) {
//            Logger.getLogger(FormPembayaran.class.getName()).log(Level.SEVERE, null, ex);
//        }
    }//GEN-LAST:event_bsaveActionPerformed

    private void tTotalBayarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tTotalBayarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tTotalBayarActionPerformed

    private void tDibayarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tDibayarActionPerformed
        // TODO add your handling code here:
        double a = Double.parseDouble(tTotalBayar.getText());
        double b = Double.parseDouble(tDibayar.getText());
        double total = a - b;
        tBelumDibayar.setText(Double.toString(total));
    }//GEN-LAST:event_tDibayarActionPerformed

    private void tNisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tNisActionPerformed
        // TODO add your handling code here:
//         if (java.awt.event.KeyEvent.VK_ENTER == evt.getKeyCode()) {
        try {
            // TODO add your handling code here:

            TagihanSiswa s = Kontrol.getKoneksiTagihan().getDataTagihanOtomatis(tNis.getText());
            if (s != null) {
                tNama.setText(s.getNama());
                tKelas.setText(s.getNama_kelas());
                tTotalBayar.setText(s.getTotal().toString());
//                    tDibayar.setText(s.getBiayaBulan().toString());

            } else {
            }
        } catch (SQLException ex) {
            Logger.getLogger(FormPembayaran.class.getName()).log(Level.SEVERE, null, ex);
        }


    }//GEN-LAST:event_tNisActionPerformed

    private void bCetakActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bCetakActionPerformed
        // TODO add your handling code here:
        String no = tNomerTransaksi.getText();
        try {
            Connection kon = null;
            String reportSource = "";
            kon = koneksi.getDBConnection();

            reportSource = "./report/kwitansi.jasper";


            Map<String, Object> params = new HashMap<String, Object>();
            params.put("notransaksi", no);
            try {
                JasperPrint jasperPrint = JasperFillManager.fillReport(reportSource, params, kon);
                JasperViewer.viewReport(jasperPrint, false);

            } catch (JRException ex) {
                ex.printStackTrace();
            }

            this.setExtendedState(JFrame.ICONIFIED);

        } catch (Exception ex) {
            Logger.getLogger(FormPembayaran.class.getName()).log(Level.SEVERE, null, ex);
        }
        notransaksi();


        try {
            TagihanSiswa ts = new TagihanSiswa();
            ts.setNIS(tNis.getText());
            String nomor = Kontrol.getKoneksiTagihan().getDatanoTelpon(tNis.getText());
            System.out.println(nomor);
            ts.setNo_tlepn(nomor);
            Kontrol1.getKoneksisms().smsGateway(ts);
        } catch (Exception ex) {
            Logger.getLogger(FormPembayaran.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_bCetakActionPerformed

    public void kosongkan() {
        tNis.setText("");
        tNama.setText("");
        tKelas.setText("");
        tTotalBayar.setText("");
        tDibayar.setText("");
        tBelumDibayar.setText("");
        tNis.requestFocus();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FormPembayaran.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormPembayaran.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormPembayaran.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormPembayaran.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FormPembayaran().setVisible(true);
            }
        });

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bCetak;
    private javax.swing.JButton bsave;
    private javax.swing.JToggleButton btnBatal;
    private javax.swing.JToggleButton btnKeluar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTextField tBelumDibayar;
    private javax.swing.JTextField tDibayar;
    private javax.swing.JTextField tKelas;
    private javax.swing.JTextField tNama;
    private javax.swing.JTextField tNis;
    private javax.swing.JTextField tNomerTransaksi;
    private com.toedter.calendar.JDateChooser tTanggal;
    private javax.swing.JTextField tTotalBayar;
    // End of variables declaration//GEN-END:variables

    public final String notransaksi() {
        try {
            String sql = "select max(notransaksi) from pembayaran";
            Connection con = tools.koneksi.getDBConnection();
            java.sql.Statement sta = con.createStatement();
            ResultSet rs = sta.executeQuery(sql);

            rs.next();
            String result = rs.getString(1);
            if (result != null) {
                int no = Integer.parseInt(result);
                no++;
                sql = "" + no;
                while (sql.length() <= 3) {
                    sql = "0" + sql;

                }
                tNomerTransaksi.setText(sql);
            } else {
                sql = "0001";
                tNomerTransaksi.setText(sql);
            }
            return sql;

        } catch (SQLException ex) {
            Logger.getLogger(FormKelolaTagihan.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }
}
